home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1996 / MacHack 1996.toast / Hacks / Hacks ’87 / Source ƒ.sit / Source ƒ / emacs source ƒ / EGAPC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  6.6 KB  |  320 lines  |  [TEXT/MARC]

  1. /*
  2.  * The routines in this file provide support for the IBM-PC EGA and other
  3.  * compatible terminals. It goes directly to the graphics RAM to do
  4.  * screen output. It compiles into nothing if not an IBM-PC EGA driver
  5.  */
  6.  
  7. #define    termdef    1            /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     EGA
  14.  
  15. #define NROW    43                      /* Screen size.                 */
  16. #define NCOL    80                      /* Edit if you want to.         */
  17. #define    MARGIN    8            /* size of minimim margin and    */
  18. #define    SCRSIZ    64            /* scroll size for extended lines */
  19. #define    NPAUSE    200            /* # times thru update to pause */
  20. #define BEL     0x07                    /* BEL character.               */
  21. #define ESC     0x1B                    /* ESC character.               */
  22. #define    SPACE    32            /* space character        */
  23. #define    SCADD    0xb8000000L        /* address of screen RAM    */
  24.  
  25. int *scptr[NROW];            /* pointer to screen lines    */
  26. int sline[NCOL];            /* screen line image        */
  27.  
  28. extern  int     ttopen();               /* Forward references.          */
  29. extern  int     ttgetc();
  30. extern  int     ttputc();
  31. extern  int     ttflush();
  32. extern  int     ttclose();
  33. extern    int    egakopen();
  34. extern    int    egakclose();
  35. extern  int     egamove();
  36. extern  int     egaeeol();
  37. extern  int     egaeeop();
  38. extern  int     egabeep();
  39. extern  int     egaopen();
  40. extern    int    egarev();
  41. extern    int    egaclose();
  42. extern    int    egaputc();
  43.  
  44. #if    COLOR
  45. extern    int    egafcol();
  46. extern    int    egabcol();
  47.  
  48. int    cfcolor = -1;        /* current forground color */
  49. int    cbcolor = -1;        /* current background color */
  50. int    ctrans[] =        /* ansi to ega color translation table */
  51.     {0, 4, 2, 6, 1, 5, 3, 7};
  52. #endif
  53.  
  54. /*
  55.  * Standard terminal interface dispatch table. Most of the fields point into
  56.  * "termio" code.
  57.  */
  58. TERM    term    = {
  59.         NROW-1,
  60.         NCOL,
  61.     MARGIN,
  62.     SCRSIZ,
  63.     NPAUSE,
  64.         egaopen,
  65.         egaclose,
  66.     egakopen,
  67.     egakclose,
  68.         ttgetc,
  69.     egaputc,
  70.         ttflush,
  71.         egamove,
  72.         egaeeol,
  73.         egaeeop,
  74.         egabeep,
  75.     egarev
  76. #if    COLOR
  77.     , egafcol,
  78.     egabcol
  79. #endif
  80. };
  81.  
  82. extern union REGS rg;
  83.  
  84. #if    COLOR
  85. egafcol(color)        /* set the current output color */
  86.  
  87. int color;    /* color to set */
  88.  
  89. {
  90.     cfcolor = ctrans[color];
  91. }
  92.  
  93. egabcol(color)        /* set the current background color */
  94.  
  95. int color;    /* color to set */
  96.  
  97. {
  98.         cbcolor = ctrans[color];
  99. }
  100. #endif
  101.  
  102. egamove(row, col)
  103. {
  104.     rg.h.ah = 2;        /* set cursor position function code */
  105.     rg.h.dl = col;
  106.     rg.h.dh = row;
  107.     rg.h.bh = 0;        /* set screen page number */
  108.     int86(0x10, &rg, &rg);
  109. }
  110.  
  111. egaeeol()    /* erase to the end of the line */
  112.  
  113. {
  114.     int attr;    /* attribute byte mask to place in RAM */
  115.     int *lnptr;    /* pointer to the destination line */
  116.     int i;
  117.     int ccol;    /* current column cursor lives */
  118.     int crow;    /*       row    */
  119.  
  120.     /* find the current cursor position */
  121.     rg.h.ah = 3;        /* read cursor position function code */
  122.     rg.h.bh = 0;        /* current video page */
  123.     int86(0x10, &rg, &rg);
  124.     ccol = rg.h.dl;        /* record current column */
  125.     crow = rg.h.dh;        /* and row */
  126.  
  127.     /* build the attribute byte and setup the screen pointer */
  128. #if    COLOR
  129.     attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  130. #else
  131.     attr = 0x0700;
  132. #endif
  133.     lnptr = &sline[0];
  134.     for (i=0; i < NCOL; i++)
  135.         *lnptr++ = SPACE | attr;
  136.  
  137.     /* wait for vertical retrace to be off */
  138.     while ((inp(0x3da) & 8))
  139.         ;
  140.  
  141.     /* and to be back on */
  142.     while ((inp(0x3da) & 8) == 0)
  143.         ;
  144.  
  145.     /* and send the string out */
  146.     movmem(&sline[0], scptr[crow]+ccol, (NCOL-ccol)*2);
  147.  
  148. }
  149.  
  150. egaputc(ch)    /* put a character at the current position in the
  151.            current colors */
  152.  
  153. int ch;
  154.  
  155. {
  156.     rg.h.ah = 14;        /* write char to screen with current attrs */
  157.     rg.h.al = ch;
  158. #if    COLOR
  159.     rg.h.bl = cfcolor;
  160. #else
  161.     rg.h.bl = 0x07;
  162. #endif
  163.     int86(0x10, &rg, &rg);
  164. }
  165.  
  166. egaeeop()
  167. {
  168.     int attr;        /* attribute to fill screen with */
  169.  
  170.     rg.h.ah = 6;        /* scroll page up function code */
  171.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  172.     rg.x.cx = 0;        /* upper left corner of scroll */
  173.     rg.x.dx = 0x2a4f;    /* lower right corner of scroll */
  174. #if    COLOR
  175.     attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  176. #else
  177.     attr = 0;
  178. #endif
  179.     rg.h.bh = attr;
  180.     int86(0x10, &rg, &rg);
  181. }
  182.  
  183. egarev(state)        /* change reverse video state */
  184.  
  185. int state;    /* TRUE = reverse, FALSE = normal */
  186.  
  187. {
  188.     /* This never gets used under the ega-PC driver */
  189. }
  190.  
  191. egabeep()
  192. {
  193.     bdos(6, BEL, 0);
  194. }
  195.  
  196. egaopen()
  197. {
  198.     char buf;    /* buffer for peek/poke */
  199.  
  200.     /* initialize pointers to the screen ram */
  201.     scinit();
  202.  
  203.     /* and put the beast into EGA 43 row mode */
  204.     rg.x.ax = 3;
  205.     int86(0x10, &rg, &rg);
  206.  
  207.     rg.x.ax = 0x1112;
  208.     rg.h.bl = 0;
  209.     int86(0x10, &rg, &rg);
  210.  
  211.     peek(0x40, 0x87, &buf, 1);
  212.     buf |= 1;
  213.     poke(0x40, 0x87, &buf, 1);
  214.  
  215.     rg.x.ax = 0x0100;
  216.     rg.h.bh = 0;
  217.     rg.x.cx = 0x0007;
  218.     int86(0x10, &rg, &rg);
  219.  
  220.     revexist = TRUE;
  221.         ttopen();
  222. }
  223.  
  224. egaclose()
  225.  
  226. {
  227. #if    COLOR
  228.     egafcol(7);
  229.     egabcol(0);
  230. #endif
  231.     /* and put the beast into 80 column mode */
  232.     rg.x.ax = 0002;
  233.     int86(0x10, &rg, &rg);
  234.     ttclose();
  235.  
  236.     /* and restore the normal cursor */
  237.     rg.x.ax = 0x0100;
  238.     rg.h.bl = 0;
  239.     rg.x.cx = 0x0b0d;
  240.     int86(0x10, &rg, &rg);
  241. }
  242.  
  243. egakopen()
  244.  
  245. {
  246. }
  247.  
  248. egakclose()
  249.  
  250. {
  251. }
  252.  
  253. scinit()    /* initialize the screen head pointers */
  254.  
  255. {
  256.     union {
  257.         long laddr;    /* long form of address */
  258.         int *paddr;    /* pointer form of address */
  259.     } addr;
  260.     int i;
  261.  
  262.     /* initialize the screen pointer array */
  263.     for (i = 0; i < NROW; i++) {
  264.         addr.laddr = SCADD + (long)(NCOL * i * 2);
  265.         scptr[i] = addr.paddr;
  266.     }
  267. }
  268.  
  269. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  270.  
  271. int row;    /* row of screen to place outstr on */
  272. char *outstr;    /* string to write out (must be NCOL long) */
  273. int forg;    /* forground color of string to write */
  274. int bacg;    /* background color */
  275.  
  276. {
  277.     int attr;    /* attribute byte mask to place in RAM */
  278.     int *lnptr;    /* pointer to the destination line */
  279.     int i;
  280.  
  281.     /* build the attribute byte and setup the screen pointer */
  282. #if    COLOR
  283.     attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  284. #else
  285.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  286. #endif
  287.     lnptr = &sline[0];
  288.     for (i=0; i<NCOL; i++)
  289.         *lnptr++ = (outstr[i] & 255) | attr;
  290.  
  291. #if    FLICKER
  292.     /* wait for vertical retrace to be off */
  293.     while ((inp(0x3da) & 8))
  294.         ;
  295.  
  296.     /* and to be back on */
  297.     while ((inp(0x3da) & 8) == 0)
  298.         ;
  299. #endif
  300.  
  301.     /* and send the string out */
  302.     movmem(&sline[0], scptr[row],NCOL*2);
  303. }
  304.  
  305. #if    FLABEL
  306. fnclabel(f, n)        /* label a function key */
  307.  
  308. int f,n;    /* default flag, numeric argument [unused] */
  309.  
  310. {
  311.     /* on machines with no function keys...don't bother */
  312.     return(TRUE);
  313. }
  314. #endif
  315. #else
  316. egahello()
  317. {
  318. }
  319. #endif
  320.